<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数组转对象</title>
</head>
<body>
    <script>
        function transform(arr) {
            var obj = {}, length = 0, newArr = arr.sort();
            for (var i = 0, j = 1 ; i < arr.length - 2 ; i = j) {
                while(newArr[i] === newArr[j]) {
                    j++;
                }
                length = j - i;
                obj[newArr[i]] = length;
            }
            return obj
        }
        console.log(transform(['a','a','b','b','c','c','c','c','d','d','d','d','a'] ))
    </script>
</body>
</html>